package com.gsoe.auth.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gsoe.auth.dto.UserProblemCollectDTO;
import com.gsoe.base.model.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserInfoMapper extends BaseMapper<User> {
    @Select("SELECT DISTINCT p.power_name FROM role_power AS rp inner JOIN power AS p ON rp.power_id = p.id\n" +
            "WHERE rp.role_id IN (SELECT ur.role_id FROM user_role AS ur inner join role as r on ur.role_id = r.id WHERE r.role_name=#{roleName})")
    List<String> getPowerListByRoleName(@Param("roleName") String roleName);
    @Select("SELECT r.role_name FROM user_role AS ur inner JOIN role AS r ON ur.role_id = r.id WHERE ur.user_id=#{id}")
    List<String> getRoleList(@Param("id") Long id);

    @Insert("INSERT INTO user_problem_collect(user_id,problem_id,problem_describe)VALUES (#{userId},#{problemId},#{problemDescribe})")
    void addUserProblemCollect(UserProblemCollectDTO userProblemCollectDTO);

    @Delete("DELETE FROM user.user_problem_collect WHERE problem_id=#{problemId} and user_id=#{userId}")
    void deleteUserProblemCollect(@Param("problemId")Long problemId,@Param("userId")Long userId);
}
